﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;

namespace SystemModule
{
    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
    public class TNakedAbility // Size 24
    {
        public ushort DC;
        public ushort MC;
        public ushort SC;
        public ushort AC;
        public ushort MAC;
        public int HP;
        public int MP;
        public ushort Hit;
        public ushort Speed;
        public ushort X2;

        public TNakedAbility()
        {

        }

        public TNakedAbility(byte[] buff)
        {
            DC = BitConverter.ToUInt16(buff, 0);
            MC = BitConverter.ToUInt16(buff, 2);
            SC = BitConverter.ToUInt16(buff, 4);
            AC = BitConverter.ToUInt16(buff, 6);
            MAC = BitConverter.ToUInt16(buff, 8);
            HP = BitConverter.ToInt32(buff, 12);
            MP = BitConverter.ToInt32(buff, 16);
            Hit = BitConverter.ToUInt16(buff, 18);
            Speed = BitConverter.ToUInt16(buff, 20);
            X2 = BitConverter.ToUInt16(buff, 22);
        }

        public byte[] ToByte()
        {
            using (var memoryStream = new MemoryStream())
            {
                var backingStream = new BinaryWriter(memoryStream);
                backingStream.Write(DC);
                backingStream.Write(MC);
                backingStream.Write(SC);
                backingStream.Write(AC);
                backingStream.Write(MAC);
                backingStream.Write(HP);
                backingStream.Write(MP);
                backingStream.Write(Hit);
                backingStream.Write(Speed);
                backingStream.Write(X2);
                var stream = backingStream.BaseStream as MemoryStream;
                return stream.ToArray();
            }
        }
    }
}